﻿namespace UnityEditor
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.CompilerServices;
    using UnityEditorInternal;
    using UnityEngine;

    [CustomEditor(typeof(LODGroup))]
    internal class LODGroupEditor : Editor
    {
        [CompilerGenerated]
        private static Func<UnityEngine.Object, GameObject> <>f__am$cache10;
        [CompilerGenerated]
        private static Func<UnityEngine.Object, bool> <>f__am$cache11;
        [CompilerGenerated]
        private static Func<UnityEngine.Object, UnityEngine.Renderer> <>f__am$cache12;
        [CompilerGenerated]
        private static Func<LODInfo, bool> <>f__am$cache13;
        [CompilerGenerated]
        private static Func<LODInfo, int> <>f__am$cache14;
        [CompilerGenerated]
        private static Func<LODInfo, bool> <>f__am$cache15;
        [CompilerGenerated]
        private static Func<LODInfo, int> <>f__am$cache16;
        [CompilerGenerated]
        private static Func<UnityEngine.Object, bool> <>f__am$cache17;
        [CompilerGenerated]
        private static Func<UnityEngine.Object, GameObject> <>f__am$cache18;
        [CompilerGenerated]
        private static Func<Vector3, Vector2> <>f__am$cacheE;
        [CompilerGenerated]
        private static Func<UnityEngine.Object, bool> <>f__am$cacheF;
        private static readonly Color kCulledLODColor = new Color(0.4f, 0f, 0f, 1f);
        private static readonly Color[] kLODColors = new Color[] { new Color(0.4831376f, 0.6211768f, 0.0219608f, 1f), new Color(0.279216f, 0.4078432f, 0.5835296f, 1f), new Color(0.2070592f, 0.5333336f, 0.6556864f, 1f), new Color(0.5333336f, 0.16f, 0.0282352f, 1f), new Color(0.3827448f, 0.2886272f, 0.5239216f, 1f), new Color(0.8f, 0.4423528f, 0f, 1f), new Color(0.4486272f, 0.4078432f, 0.050196f, 1f), new Color(0.7749016f, 0.6368624f, 0.0250984f, 1f) };
        private const string kLODDataPath = "m_LODs.Array.data[{0}]";
        private const string kLODRootPath = "m_LODs";
        private const string kPixelHeightDataPath = "m_LODs.Array.data[{0}].screenRelativeHeight";
        private const string kRenderRootPath = "m_LODs.Array.data[{0}].renderers";
        private static readonly GUIContent[] kSLightIcons = new GUIContent[2];
        private readonly int m_CameraSliderId = "LODCameraIDHash".GetHashCode();
        private bool m_IsPrefab;
        private Vector3 m_LastCameraPos = Vector3.zero;
        private readonly int m_LODSliderId = "LODSliderIDHash".GetHashCode();
        private int m_NumberOfLODs;
        private SerializedObject m_Object;
        private Vector2 m_PreviewDir = new Vector2(0f, -20f);
        private PreviewRenderUtility m_PreviewUtility;
        private int m_SelectedLOD = -1;
        private int m_SelectedLODSlider = -1;
        private static Styles s_Styles;

        private void AddGameObjectRenderers(IEnumerable<UnityEngine.Renderer> toAdd, bool add)
        {
            SerializedProperty property = this.m_Object.FindProperty(string.Format("m_LODs.Array.data[{0}].renderers", this.activeLOD));
            if (!add)
            {
                property.ClearArray();
            }
            List<UnityEngine.Renderer> list = new List<UnityEngine.Renderer>();
            for (int i = 0; i < property.arraySize; i++)
            {
                UnityEngine.Renderer objectReferenceValue = property.GetArrayElementAtIndex(i).FindPropertyRelative("renderer").objectReferenceValue as UnityEngine.Renderer;
                if (objectReferenceValue != null)
                {
                    list.Add(objectReferenceValue);
                }
            }
            IEnumerator<UnityEngine.Renderer> enumerator = toAdd.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    UnityEngine.Renderer current = enumerator.Current;
                    if (!list.Contains(current))
                    {
                        property.arraySize++;
                        property.GetArrayElementAtIndex(property.arraySize - 1).FindPropertyRelative("renderer").objectReferenceValue = current;
                        list.Add(current);
                    }
                }
            }
            finally
            {
                if (enumerator == null)
                {
                }
                enumerator.Dispose();
            }
            this.m_Object.ApplyModifiedProperties();
            LODUtility.CalculateLODGroupBoundingBox(base.target as LODGroup);
        }

        private static Rect CalcLODButton(Rect totalRect, float percentage)
        {
            return new Rect((totalRect.x + Mathf.Round(totalRect.width * (1f - percentage))) - 5f, totalRect.y, 10f, totalRect.height);
        }

        private static Rect CalcLODRange(Rect totalRect, float startPercent, float endPercent)
        {
            float num = Mathf.Round(totalRect.width * (1f - startPercent));
            float num2 = Mathf.Round(totalRect.width * (1f - endPercent));
            return new Rect(totalRect.x + num, totalRect.y, num2 - num, totalRect.height);
        }

        private static float CalculatePercentageFromBar(Rect totalRect, Vector2 clickPosition)
        {
            clickPosition.x -= totalRect.x;
            totalRect.x = 0f;
            return ((totalRect.width <= 0f) ? 0f : (1f - (clickPosition.x / totalRect.width)));
        }

        private static Rect CalculateScreenRect(IEnumerable<Vector3> points)
        {
            if (<>f__am$cacheE == null)
            {
                <>f__am$cacheE = p => HandleUtility.WorldToGUIPoint(p);
            }
            List<Vector2> list = Enumerable.Select<Vector3, Vector2>(points, <>f__am$cacheE).ToList<Vector2>();
            Vector2 vector = new Vector2(float.MaxValue, float.MaxValue);
            Vector2 vector2 = new Vector2(float.MinValue, float.MinValue);
            foreach (Vector2 vector3 in list)
            {
                vector.x = (vector3.x >= vector.x) ? vector.x : vector3.x;
                vector2.x = (vector3.x <= vector2.x) ? vector2.x : vector3.x;
                vector.y = (vector3.y >= vector.y) ? vector.y : vector3.y;
                vector2.y = (vector3.y <= vector2.y) ? vector2.y : vector3.y;
            }
            return new Rect(vector.x, vector.y, vector2.x - vector.x, vector2.y - vector.y);
        }

        private void DeletedLOD()
        {
            this.m_SelectedLOD--;
        }

        private static float DelinearizeScreenPercentage(float percentage)
        {
            if (Mathf.Approximately(0f, percentage))
            {
                return 0f;
            }
            return Mathf.Sqrt(percentage);
        }

        protected void DoRenderPreview()
        {
            if (((this.m_PreviewUtility.m_RenderTexture.width > 0) && (this.m_PreviewUtility.m_RenderTexture.height > 0)) && ((this.m_NumberOfLODs > 0) && (this.activeLOD >= 0)))
            {
                Bounds bounds = new Bounds(Vector3.zero, Vector3.zero);
                bool flag = false;
                List<MeshFilter> list = new List<MeshFilter>();
                SerializedProperty property = this.m_Object.FindProperty(string.Format("m_LODs.Array.data[{0}].renderers", this.activeLOD));
                for (int i = 0; i < property.arraySize; i++)
                {
                    UnityEngine.Renderer objectReferenceValue = property.GetArrayElementAtIndex(i).FindPropertyRelative("renderer").objectReferenceValue as UnityEngine.Renderer;
                    if (objectReferenceValue != null)
                    {
                        MeshFilter component = objectReferenceValue.GetComponent<MeshFilter>();
                        if (((component != null) && (component.sharedMesh != null)) && (component.sharedMesh.subMeshCount > 0))
                        {
                            list.Add(component);
                        }
                        if (!flag)
                        {
                            bounds = objectReferenceValue.bounds;
                            flag = true;
                        }
                        else
                        {
                            bounds.Encapsulate(objectReferenceValue.bounds);
                        }
                    }
                }
                if (flag)
                {
                    float num3 = bounds.extents.magnitude * 10f;
                    Vector2 vector = (Vector2) -(this.m_PreviewDir / 100f);
                    float introduced18 = Mathf.Sin(vector.x);
                    float y = Mathf.Sin(vector.y);
                    float introduced20 = Mathf.Cos(vector.x);
                    this.m_PreviewUtility.m_Camera.transform.position = bounds.center + ((Vector3) (new Vector3(introduced18 * Mathf.Cos(vector.y), y, introduced20 * Mathf.Cos(vector.y)) * num3));
                    this.m_PreviewUtility.m_Camera.transform.LookAt(bounds.center);
                    this.m_PreviewUtility.m_Camera.nearClipPlane = 0.05f;
                    this.m_PreviewUtility.m_Camera.farClipPlane = 1000f;
                    this.m_PreviewUtility.m_Light[0].intensity = 0.5f;
                    this.m_PreviewUtility.m_Light[0].transform.rotation = Quaternion.Euler(50f, 50f, 0f);
                    this.m_PreviewUtility.m_Light[1].intensity = 0.5f;
                    Color ambient = new Color(0.2f, 0.2f, 0.2f, 0f);
                    InternalEditorUtility.SetCustomLighting(this.m_PreviewUtility.m_Light, ambient);
                    foreach (MeshFilter filter2 in list)
                    {
                        for (int j = 0; j < filter2.sharedMesh.subMeshCount; j++)
                        {
                            if (j < filter2.renderer.sharedMaterials.Length)
                            {
                                Matrix4x4 matrix = Matrix4x4.TRS(filter2.transform.position, filter2.transform.rotation, filter2.transform.localScale);
                                this.m_PreviewUtility.DrawMesh(filter2.sharedMesh, matrix, filter2.renderer.sharedMaterials[j], j);
                            }
                        }
                    }
                    bool fog = RenderSettings.fog;
                    Unsupported.SetRenderSettingsUseFogNoDirty(false);
                    this.m_PreviewUtility.m_Camera.Render();
                    Unsupported.SetRenderSettingsUseFogNoDirty(fog);
                    InternalEditorUtility.RemoveCustomLighting();
                }
            }
        }

        private static void DrawCulledRange(Rect totalRect, float previousLODPercentage)
        {
            if (!Mathf.Approximately(previousLODPercentage, 0f))
            {
                Rect culledBox = GetCulledBox(totalRect, DelinearizeScreenPercentage(previousLODPercentage));
                Color color = GUI.color;
                GUI.color = kCulledLODColor;
                s_Styles.m_LODSliderRange.Draw(culledBox, GUIContent.none, false, false, false, false);
                GUI.color = color;
                string text = string.Format("Culled\n{0:0}%", previousLODPercentage * 100f);
                s_Styles.m_LODSliderText.Draw(culledBox, text, false, false, false, false);
            }
        }

        private static void DrawLODButton(LODInfo currentLOD)
        {
            EditorGUIUtility.AddCursorRect(currentLOD.m_ButtonPosition, MouseCursor.ResizeHorizontal);
        }

        private void DrawLODLevelSlider(Rect sliderPosition, List<LODInfo> lods)
        {
            int controlID = GUIUtility.GetControlID(this.m_LODSliderId, FocusType.Passive);
            int num2 = GUIUtility.GetControlID(this.m_CameraSliderId, FocusType.Passive);
            Event current = Event.current;
            LODGroup target = base.target as LODGroup;
            if (target != null)
            {
                EventType typeForControl = current.GetTypeForControl(controlID);
                switch (typeForControl)
                {
                    case EventType.MouseDown:
                    {
                        if ((current.button != 1) || !sliderPosition.Contains(current.mousePosition))
                        {
                            Rect rect2 = sliderPosition;
                            rect2.x -= 5f;
                            rect2.width += 10f;
                            if (rect2.Contains(current.mousePosition))
                            {
                                current.Use();
                                GUIUtility.hotControl = controlID;
                                bool flag3 = false;
                                if (<>f__am$cache13 == null)
                                {
                                    <>f__am$cache13 = lod => lod.ScreenPercent > 0.5f;
                                }
                                if (<>f__am$cache14 == null)
                                {
                                    <>f__am$cache14 = x => x.m_LODLevel;
                                }
                                IOrderedEnumerable<LODInfo> collection = Enumerable.OrderByDescending<LODInfo, int>(Enumerable.Where<LODInfo>(lods, <>f__am$cache13), <>f__am$cache14);
                                if (<>f__am$cache15 == null)
                                {
                                    <>f__am$cache15 = lod => lod.ScreenPercent <= 0.5f;
                                }
                                if (<>f__am$cache16 == null)
                                {
                                    <>f__am$cache16 = x => x.m_LODLevel;
                                }
                                IOrderedEnumerable<LODInfo> enumerable2 = Enumerable.OrderBy<LODInfo, int>(Enumerable.Where<LODInfo>(lods, <>f__am$cache15), <>f__am$cache16);
                                List<LODInfo> list = new List<LODInfo>();
                                list.AddRange(collection);
                                list.AddRange(enumerable2);
                                foreach (LODInfo info3 in list)
                                {
                                    if (info3.m_ButtonPosition.Contains(current.mousePosition))
                                    {
                                        this.m_SelectedLODSlider = info3.m_LODLevel;
                                        flag3 = true;
                                        if (((SceneView.lastActiveSceneView != null) && (SceneView.lastActiveSceneView.camera != null)) && !this.m_IsPrefab)
                                        {
                                            UpdateCamera(info3.RawScreenPercent + 0.001f, target);
                                            SceneView.lastActiveSceneView.ClearSearchFilter();
                                            SceneView.lastActiveSceneView.SetSceneViewFiltering(true);
                                            HierarchyProperty.FilterSingleSceneObject(target.gameObject.GetInstanceID(), false);
                                            SceneView.RepaintAll();
                                        }
                                        break;
                                    }
                                }
                                if (!flag3)
                                {
                                    foreach (LODInfo info4 in lods)
                                    {
                                        if (info4.m_RangePosition.Contains(current.mousePosition))
                                        {
                                            this.m_SelectedLOD = info4.m_LODLevel;
                                            break;
                                        }
                                    }
                                }
                            }
                            break;
                        }
                        float percentage = CalculatePercentageFromBar(sliderPosition, current.mousePosition);
                        GenericMenu menu = new GenericMenu();
                        if (lods.Count < 8)
                        {
                            menu.AddItem(EditorGUIUtility.TextContent("Insert Before"), false, new GenericMenu.MenuFunction(new LODAction(lods, LinearizeScreenPercentage(percentage), current.mousePosition, this.m_Object, null).InsertLOD));
                        }
                        else
                        {
                            menu.AddDisabledItem(EditorGUIUtility.TextContent("Insert Before"));
                        }
                        bool flag = true;
                        if ((lods.Count > 0) && (lods[lods.Count - 1].ScreenPercent < percentage))
                        {
                            flag = false;
                        }
                        if (flag)
                        {
                            menu.AddDisabledItem(EditorGUIUtility.TextContent("Delete"));
                        }
                        else
                        {
                            menu.AddItem(EditorGUIUtility.TextContent("Delete"), false, new GenericMenu.MenuFunction(new LODAction(lods, LinearizeScreenPercentage(percentage), current.mousePosition, this.m_Object, new LODAction.Callback(this.DeletedLOD)).DeleteLOD));
                        }
                        menu.ShowAsContext();
                        bool flag2 = false;
                        foreach (LODInfo info2 in lods)
                        {
                            if (info2.m_RangePosition.Contains(current.mousePosition))
                            {
                                this.m_SelectedLOD = info2.m_LODLevel;
                                flag2 = true;
                                break;
                            }
                        }
                        if (!flag2)
                        {
                            this.m_SelectedLOD = -1;
                        }
                        current.Use();
                        break;
                    }
                    case EventType.MouseUp:
                        if (GUIUtility.hotControl == controlID)
                        {
                            GUIUtility.hotControl = 0;
                            this.m_SelectedLODSlider = -1;
                            if (SceneView.lastActiveSceneView != null)
                            {
                                SceneView.lastActiveSceneView.SetSceneViewFiltering(false);
                                SceneView.lastActiveSceneView.ClearSearchFilter();
                            }
                            current.Use();
                        }
                        break;

                    case EventType.MouseDrag:
                        if (((GUIUtility.hotControl == controlID) && (this.m_SelectedLODSlider >= 0)) && (lods[this.m_SelectedLODSlider] != null))
                        {
                            current.Use();
                            float num5 = Mathf.Clamp01(1f - ((current.mousePosition.x - sliderPosition.x) / sliderPosition.width));
                            this.SetSelectedLODLevelPercentage(num5 - 0.001f, lods);
                            if (((SceneView.lastActiveSceneView != null) && (SceneView.lastActiveSceneView.camera != null)) && !this.m_IsPrefab)
                            {
                                UpdateCamera(LinearizeScreenPercentage(num5), target);
                                SceneView.RepaintAll();
                            }
                        }
                        break;

                    case EventType.Repaint:
                    {
                        Rect rect = sliderPosition;
                        rect.width += 2f;
                        rect.height += 2f;
                        rect.center -= new Vector2(1f, 1f);
                        s_Styles.m_LODSliderBG.Draw(sliderPosition, GUIContent.none, false, false, false, false);
                        for (int i = 0; i < lods.Count; i++)
                        {
                            LODInfo currentLOD = lods[i];
                            this.DrawLODRange(currentLOD, (i != 0) ? lods[i - 1].RawScreenPercent : 1f);
                            DrawLODButton(currentLOD);
                        }
                        DrawCulledRange(sliderPosition, (lods.Count <= 0) ? 1f : lods[lods.Count - 1].RawScreenPercent);
                        break;
                    }
                    case EventType.DragUpdated:
                    case EventType.DragPerform:
                    {
                        int lODLevel = -2;
                        foreach (LODInfo info5 in lods)
                        {
                            if (info5.m_RangePosition.Contains(current.mousePosition))
                            {
                                lODLevel = info5.m_LODLevel;
                                break;
                            }
                        }
                        if ((lODLevel == -2) && GetCulledBox(sliderPosition, (lods.Count <= 0) ? 1f : lods[lods.Count - 1].ScreenPercent).Contains(current.mousePosition))
                        {
                            lODLevel = -1;
                        }
                        if (lODLevel >= -1)
                        {
                            this.m_SelectedLOD = lODLevel;
                            if (DragAndDrop.objectReferences.Count<UnityEngine.Object>() > 0)
                            {
                                DragAndDrop.visualMode = !this.m_IsPrefab ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.None;
                                if (current.type == EventType.DragPerform)
                                {
                                    if (<>f__am$cache17 == null)
                                    {
                                        <>f__am$cache17 = go => go is GameObject;
                                    }
                                    if (<>f__am$cache18 == null)
                                    {
                                        <>f__am$cache18 = go => go as GameObject;
                                    }
                                    IEnumerable<GameObject> selectedGameObjects = Enumerable.Select<UnityEngine.Object, GameObject>(Enumerable.Where<UnityEngine.Object>(DragAndDrop.objectReferences, <>f__am$cache17), <>f__am$cache18);
                                    IEnumerable<UnityEngine.Renderer> renderers = this.GetRenderers(selectedGameObjects, true);
                                    if (lODLevel == -1)
                                    {
                                        SerializedProperty property1 = this.m_Object.FindProperty("m_LODs");
                                        property1.arraySize++;
                                        SerializedProperty property2 = this.m_Object.FindProperty(string.Format("m_LODs.Array.data[{0}].screenRelativeHeight", lods.Count));
                                        if (lods.Count == 0)
                                        {
                                            property2.floatValue = 0.5f;
                                        }
                                        else
                                        {
                                            SerializedProperty property3 = this.m_Object.FindProperty(string.Format("m_LODs.Array.data[{0}].screenRelativeHeight", lods.Count - 1));
                                            property2.floatValue = property3.floatValue / 2f;
                                        }
                                        this.m_SelectedLOD = lods.Count;
                                        this.AddGameObjectRenderers(renderers, false);
                                    }
                                    else
                                    {
                                        this.AddGameObjectRenderers(renderers, true);
                                    }
                                    DragAndDrop.AcceptDrag();
                                }
                            }
                            current.Use();
                        }
                        break;
                    }
                    default:
                        if (typeForControl == EventType.DragExited)
                        {
                            current.Use();
                        }
                        break;
                }
                if (((SceneView.lastActiveSceneView != null) && (SceneView.lastActiveSceneView.camera != null)) && !this.m_IsPrefab)
                {
                    Camera camera = SceneView.lastActiveSceneView.camera;
                    float num7 = LODUtility.CalculateVisualizationData(camera, target, -1).activeRelativeScreenSize / QualitySettings.lodBias;
                    float num8 = DelinearizeScreenPercentage(num7);
                    Vector3 vector3 = SceneView.lastActiveSceneView.camera.transform.position - ((LODGroup) base.target).transform.position;
                    Vector3 normalized = vector3.normalized;
                    if (Vector3.Dot(camera.transform.forward, normalized) > 0f)
                    {
                        num8 = 1f;
                    }
                    Rect rect4 = CalcLODButton(sliderPosition, Mathf.Clamp01(num8));
                    Rect position = new Rect(rect4.center.x - 15f, rect4.y - 25f, 32f, 32f);
                    Rect rect6 = new Rect(rect4.center.x - 1f, rect4.y, 2f, rect4.height);
                    Rect rect7 = new Rect(position.center.x - 5f, rect6.yMax, 35f, 20f);
                    switch (current.GetTypeForControl(num2))
                    {
                        case EventType.MouseDown:
                            if (position.Contains(current.mousePosition))
                            {
                                current.Use();
                                float desiredPercentage = GetCameraPercentForCurrentQualityLevel(current.mousePosition.x, sliderPosition.x, sliderPosition.width);
                                UpdateCamera(desiredPercentage, target);
                                this.UpdateSelectedLODFromCamera(lods, desiredPercentage);
                                GUIUtility.hotControl = num2;
                                SceneView.lastActiveSceneView.ClearSearchFilter();
                                SceneView.lastActiveSceneView.SetSceneViewFiltering(true);
                                HierarchyProperty.FilterSingleSceneObject(target.gameObject.GetInstanceID(), false);
                                SceneView.RepaintAll();
                            }
                            break;

                        case EventType.MouseUp:
                            if (GUIUtility.hotControl == num2)
                            {
                                SceneView.lastActiveSceneView.SetSceneViewFiltering(false);
                                SceneView.lastActiveSceneView.ClearSearchFilter();
                                GUIUtility.hotControl = 0;
                                current.Use();
                            }
                            break;

                        case EventType.MouseDrag:
                            if (GUIUtility.hotControl == num2)
                            {
                                current.Use();
                                float cameraPercent = GetCameraPercentForCurrentQualityLevel(current.mousePosition.x, sliderPosition.x, sliderPosition.width);
                                this.UpdateSelectedLODFromCamera(lods, cameraPercent);
                                UpdateCamera(cameraPercent, target);
                                SceneView.RepaintAll();
                            }
                            break;

                        case EventType.Repaint:
                        {
                            Color backgroundColor = GUI.backgroundColor;
                            GUI.backgroundColor = new Color(backgroundColor.r, backgroundColor.g, backgroundColor.b, 0.8f);
                            s_Styles.m_LODCameraLine.Draw(rect6, false, false, false, false);
                            GUI.backgroundColor = backgroundColor;
                            GUI.Label(position, s_Styles.m_CameraIcon, GUIStyle.none);
                            s_Styles.m_LODSliderText.Draw(rect7, string.Format("{0:0}%", Mathf.Clamp01(num7) * 100f), false, false, false, false);
                            break;
                        }
                    }
                }
            }
        }

        private void DrawLODRange(LODInfo currentLOD, float previousLODPercentage)
        {
            Color backgroundColor = GUI.backgroundColor;
            string text = string.Format("LOD: {0}\n{1:0}%", currentLOD.m_LODLevel, previousLODPercentage * 100f);
            if (currentLOD.m_LODLevel == this.activeLOD)
            {
                Rect rangePosition = currentLOD.m_RangePosition;
                rangePosition.width -= 6f;
                rangePosition.height -= 6f;
                rangePosition.center += new Vector2(3f, 3f);
                s_Styles.m_LODSliderRangeSelected.Draw(currentLOD.m_RangePosition, GUIContent.none, false, false, false, false);
                GUI.backgroundColor = kLODColors[currentLOD.m_LODLevel];
                if (rangePosition.width > 0f)
                {
                    s_Styles.m_LODSliderRange.Draw(rangePosition, GUIContent.none, false, false, false, false);
                }
                s_Styles.m_LODSliderText.Draw(currentLOD.m_RangePosition, text, false, false, false, false);
            }
            else
            {
                GUI.backgroundColor = kLODColors[currentLOD.m_LODLevel];
                GUI.backgroundColor = (Color) (GUI.backgroundColor * 0.6f);
                s_Styles.m_LODSliderRange.Draw(currentLOD.m_RangePosition, GUIContent.none, false, false, false, false);
                s_Styles.m_LODSliderText.Draw(currentLOD.m_RangePosition, text, false, false, false, false);
            }
            GUI.backgroundColor = backgroundColor;
        }

        private void DrawRendererButton(Rect position, int rendererIndex)
        {
            SerializedProperty property = this.m_Object.FindProperty(string.Format("m_LODs.Array.data[{0}].renderers", this.activeLOD));
            UnityEngine.Renderer objectReferenceValue = property.GetArrayElementAtIndex(rendererIndex).FindPropertyRelative("renderer").objectReferenceValue as UnityEngine.Renderer;
            Rect rect = new Rect(position.xMax - 20f, position.yMax - 20f, 20f, 20f);
            Event current = Event.current;
            switch (current.type)
            {
                case EventType.MouseDown:
                    if (!this.m_IsPrefab && rect.Contains(current.mousePosition))
                    {
                        property.DeleteArrayElementAtIndex(rendererIndex);
                        current.Use();
                        this.m_Object.ApplyModifiedProperties();
                        LODUtility.CalculateLODGroupBoundingBox(base.target as LODGroup);
                    }
                    else if (position.Contains(current.mousePosition))
                    {
                        EditorGUIUtility.PingObject(objectReferenceValue);
                        current.Use();
                    }
                    break;

                case EventType.Repaint:
                    if (objectReferenceValue != null)
                    {
                        GUIContent content;
                        MeshFilter component = objectReferenceValue.GetComponent<MeshFilter>();
                        if ((component != null) && (component.sharedMesh != null))
                        {
                            content = new GUIContent(AssetPreview.GetAssetPreview(component.sharedMesh), objectReferenceValue.gameObject.name);
                        }
                        else if (objectReferenceValue is SkinnedMeshRenderer)
                        {
                            content = new GUIContent(AssetPreview.GetAssetPreview((objectReferenceValue as SkinnedMeshRenderer).sharedMesh), objectReferenceValue.gameObject.name);
                        }
                        else
                        {
                            content = new GUIContent(ObjectNames.NicifyVariableName(objectReferenceValue.GetType().Name), objectReferenceValue.gameObject.name);
                        }
                        s_Styles.m_LODBlackBox.Draw(position, GUIContent.none, false, false, false, false);
                        "LODRendererButton".Draw(new Rect(position.x + 2f, position.y + 2f, position.width - 4f, position.height - 4f), content, false, false, false, false);
                    }
                    else
                    {
                        s_Styles.m_LODBlackBox.Draw(position, GUIContent.none, false, false, false, false);
                        s_Styles.m_LODRendererButton.Draw(position, "<Empty>", false, false, false, false);
                    }
                    if (!this.m_IsPrefab)
                    {
                        s_Styles.m_LODBlackBox.Draw(rect, GUIContent.none, false, false, false, false);
                        s_Styles.m_LODRendererRemove.Draw(rect, s_Styles.m_IconRendererMinus, false, false, false, false);
                    }
                    break;
            }
        }

        private void DrawRenderersInfo(int horizontalNumber)
        {
            Rect position = GUILayoutUtility.GetRect(s_Styles.m_RendersTitle, s_Styles.m_LODSliderTextSelected);
            if (Event.current.type == EventType.Repaint)
            {
                EditorStyles.label.Draw(position, s_Styles.m_RendersTitle, false, false, false, false);
            }
            SerializedProperty property = this.m_Object.FindProperty(string.Format("m_LODs.Array.data[{0}].renderers", this.activeLOD));
            int num = property.arraySize + 1;
            int num2 = Mathf.CeilToInt(((float) num) / ((float) horizontalNumber));
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandWidth(true) };
            Rect rect2 = GUILayoutUtility.GetRect((float) 0f, (float) (num2 * 60), options);
            Rect rect3 = rect2;
            rect2.width -= 6f;
            rect2.x += 3f;
            GUI.Box(rect2, GUIContent.none);
            rect3.width -= 12f;
            rect3.x += 6f;
            float num3 = rect3.width / ((float) horizontalNumber);
            List<Rect> alreadyDrawn = new List<Rect>();
            for (int i = 0; i < num2; i++)
            {
                for (int j = 0; (j < horizontalNumber) && (((i * horizontalNumber) + j) < property.arraySize); j++)
                {
                    Rect item = new Rect((2f + rect3.x) + (j * num3), (2f + rect3.y) + (i * 60), num3 - 4f, 56f);
                    alreadyDrawn.Add(item);
                    this.DrawRendererButton(item, (i * horizontalNumber) + j);
                }
            }
            if (!this.m_IsPrefab)
            {
                int num6 = (num - 1) % horizontalNumber;
                int num7 = num2 - 1;
                this.HandleAddRenderer(new Rect((2f + rect3.x) + (num6 * num3), (2f + rect3.y) + (num7 * 60), num3 - 4f, 56f), alreadyDrawn, rect2);
            }
        }

        private static float GetCameraPercentForCurrentQualityLevel(float clickPosition, float sliderStart, float sliderWidth)
        {
            return LinearizeScreenPercentage(Mathf.Clamp((float) (1f - ((clickPosition - sliderStart) / sliderWidth)), (float) 0.01f, (float) 1f));
        }

        private static Rect GetCulledBox(Rect totalRect, float previousLODPercentage)
        {
            Rect rect = CalcLODRange(totalRect, previousLODPercentage, 0f);
            rect.height -= 2f;
            rect.width--;
            rect.center += new Vector2(0f, 1f);
            return rect;
        }

        private ModelImporter GetImporter()
        {
            return (AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(PrefabUtility.GetPrefabParent(base.target))) as ModelImporter);
        }

        public override string GetInfoString()
        {
            if (((SceneView.lastActiveSceneView == null) || (SceneView.lastActiveSceneView.camera == null)) || ((this.m_NumberOfLODs <= 0) || (this.activeLOD < 0)))
            {
                return string.Empty;
            }
            List<Material> source = new List<Material>();
            SerializedProperty property = this.m_Object.FindProperty(string.Format("m_LODs.Array.data[{0}].renderers", this.activeLOD));
            for (int i = 0; i < property.arraySize; i++)
            {
                UnityEngine.Renderer objectReferenceValue = property.GetArrayElementAtIndex(i).FindPropertyRelative("renderer").objectReferenceValue as UnityEngine.Renderer;
                if (objectReferenceValue != null)
                {
                    source.AddRange(objectReferenceValue.sharedMaterials);
                }
            }
            Camera camera = SceneView.lastActiveSceneView.camera;
            LODGroup target = base.target as LODGroup;
            LODVisualizationInformation information = LODUtility.CalculateVisualizationData(camera, target, this.activeLOD);
            return ((this.activeLOD == -1) ? "LOD: culled" : string.Format("{0} Renderer(s)\n{1} Triangle(s)\n{2} Material(s)", property.arraySize, information.triangleCount, source.Distinct<Material>().Count<Material>()));
        }

        private IEnumerable<UnityEngine.Renderer> GetRenderers(IEnumerable<GameObject> selectedGameObjects, bool searchChildren)
        {
            <GetRenderers>c__AnonStorey3E storeye = new <GetRenderers>c__AnonStorey3E {
                lodGroup = base.target as LODGroup
            };
            if ((storeye.lodGroup == null) || EditorUtility.IsPersistent(storeye.lodGroup))
            {
                return new List<UnityEngine.Renderer>();
            }
            IEnumerable<GameObject> first = Enumerable.Where<GameObject>(selectedGameObjects, new Func<GameObject, bool>(storeye.<>m__7F));
            IEnumerable<GameObject> source = Enumerable.Where<GameObject>(selectedGameObjects, new Func<GameObject, bool>(storeye.<>m__80));
            List<GameObject> second = new List<GameObject>();
            if ((source.Count<GameObject>() > 0) && EditorUtility.DisplayDialog("Reparent GameObjects", "Some objects are not children of the LODGroup GameObject. Do you want to reparent them and add them to the LODGroup?", "Yes, Reparent", "No, Use Only Existing Children"))
            {
                IEnumerator<GameObject> enumerator = source.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        GameObject current = enumerator.Current;
                        if (EditorUtility.IsPersistent(current))
                        {
                            GameObject item = UnityEngine.Object.Instantiate(current) as GameObject;
                            if (item != null)
                            {
                                item.transform.parent = storeye.lodGroup.transform;
                                item.transform.localPosition = Vector3.zero;
                                item.transform.localRotation = Quaternion.identity;
                                second.Add(item);
                            }
                        }
                        else
                        {
                            current.transform.parent = storeye.lodGroup.transform;
                            second.Add(current);
                        }
                    }
                }
                finally
                {
                    if (enumerator == null)
                    {
                    }
                    enumerator.Dispose();
                }
                first = first.Union<GameObject>(second);
            }
            List<UnityEngine.Renderer> list2 = new List<UnityEngine.Renderer>();
            IEnumerator<GameObject> enumerator2 = first.GetEnumerator();
            try
            {
                while (enumerator2.MoveNext())
                {
                    GameObject obj4 = enumerator2.Current;
                    if (searchChildren)
                    {
                        list2.AddRange(obj4.GetComponentsInChildren<UnityEngine.Renderer>());
                    }
                    else
                    {
                        list2.Add(obj4.GetComponent<UnityEngine.Renderer>());
                    }
                }
            }
            finally
            {
                if (enumerator2 == null)
                {
                }
                enumerator2.Dispose();
            }
            if (<>f__am$cache11 == null)
            {
                <>f__am$cache11 = go => go is UnityEngine.Renderer;
            }
            if (<>f__am$cache12 == null)
            {
                <>f__am$cache12 = go => go as UnityEngine.Renderer;
            }
            IEnumerable<UnityEngine.Renderer> collection = Enumerable.Select<UnityEngine.Object, UnityEngine.Renderer>(Enumerable.Where<UnityEngine.Object>(DragAndDrop.objectReferences, <>f__am$cache11), <>f__am$cache12);
            list2.AddRange(collection);
            return list2;
        }

        private void HandleAddRenderer(Rect position, IEnumerable<Rect> alreadyDrawn, Rect drawArea)
        {
            <HandleAddRenderer>c__AnonStorey3D storeyd = new <HandleAddRenderer>c__AnonStorey3D {
                evt = Event.current
            };
            switch (storeyd.evt.type)
            {
                case EventType.Repaint:
                    s_Styles.m_LODStandardButton.Draw(position, GUIContent.none, false, false, false, false);
                    s_Styles.m_LODRendererAddButton.Draw(new Rect(position.x - 2f, position.y, position.width, position.height), "Add", false, false, false, false);
                    return;

                case EventType.DragUpdated:
                case EventType.DragPerform:
                {
                    bool flag = false;
                    if (drawArea.Contains(storeyd.evt.mousePosition) && Enumerable.All<Rect>(alreadyDrawn, new Func<Rect, bool>(storeyd.<>m__7C)))
                    {
                        flag = true;
                    }
                    if (flag)
                    {
                        if (DragAndDrop.objectReferences.Count<UnityEngine.Object>() <= 0)
                        {
                            break;
                        }
                        DragAndDrop.visualMode = !this.m_IsPrefab ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.None;
                        if (storeyd.evt.type != EventType.DragPerform)
                        {
                            break;
                        }
                        if (<>f__am$cacheF == null)
                        {
                            <>f__am$cacheF = go => go is GameObject;
                        }
                        if (<>f__am$cache10 == null)
                        {
                            <>f__am$cache10 = go => go as GameObject;
                        }
                        IEnumerable<GameObject> selectedGameObjects = Enumerable.Select<UnityEngine.Object, GameObject>(Enumerable.Where<UnityEngine.Object>(DragAndDrop.objectReferences, <>f__am$cacheF), <>f__am$cache10);
                        IEnumerable<UnityEngine.Renderer> renderers = this.GetRenderers(selectedGameObjects, true);
                        this.AddGameObjectRenderers(renderers, true);
                        DragAndDrop.AcceptDrag();
                        storeyd.evt.Use();
                    }
                    return;
                }
                case EventType.ExecuteCommand:
                    if ((storeyd.evt.commandName == "ObjectSelectorClosed") && (ObjectSelector.get.objectSelectorID == "LODGroupSelector".GetHashCode()))
                    {
                        this.AddGameObjectRenderers(this.GetRenderers(new List<GameObject> { ObjectSelector.GetCurrentObject() as GameObject }, true), true);
                        storeyd.evt.Use();
                        GUIUtility.ExitGUI();
                    }
                    return;

                case EventType.MouseDown:
                    if (position.Contains(storeyd.evt.mousePosition))
                    {
                        storeyd.evt.Use();
                        int hashCode = "LODGroupSelector".GetHashCode();
                        ObjectSelector.get.Show(null, typeof(UnityEngine.Renderer), null, true);
                        ObjectSelector.get.objectSelectorID = hashCode;
                        GUIUtility.ExitGUI();
                    }
                    return;

                default:
                    return;
            }
            storeyd.evt.Use();
        }

        public override bool HasPreviewGUI()
        {
            return (base.target != null);
        }

        private void InitPreview()
        {
            if (this.m_PreviewUtility == null)
            {
                this.m_PreviewUtility = new PreviewRenderUtility();
            }
            if (kSLightIcons[0] == null)
            {
                kSLightIcons[0] = EditorGUIUtility.IconContent("PreMatLight0");
                kSLightIcons[1] = EditorGUIUtility.IconContent("PreMatLight1");
            }
        }

        private static float LinearizeScreenPercentage(float percentage)
        {
            return (percentage * percentage);
        }

        private void OnDisable()
        {
            EditorApplication.update = (EditorApplication.CallbackFunction) Delegate.Remove(EditorApplication.update, new EditorApplication.CallbackFunction(this.Update));
        }

        private void OnEnable()
        {
            this.m_Object = new SerializedObject(base.target);
            EditorApplication.update = (EditorApplication.CallbackFunction) Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(this.Update));
            switch (PrefabUtility.GetPrefabType(((LODGroup) base.target).gameObject))
            {
                case PrefabType.Prefab:
                case PrefabType.ModelPrefab:
                    this.m_IsPrefab = true;
                    break;

                default:
                    this.m_IsPrefab = false;
                    break;
            }
            base.Repaint();
        }

        public override void OnInspectorGUI()
        {
            bool enabled = GUI.enabled;
            if (!Application.HasProLicense())
            {
                EditorGUILayout.HelpBox("LOD only available in Unity Pro", MessageType.Warning);
                GUI.enabled = false;
            }
            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }
            this.m_Object.Update();
            this.m_NumberOfLODs = this.m_Object.FindProperty("m_LODs").arraySize;
            if ((this.m_NumberOfLODs > 0) && (this.activeLOD >= 0))
            {
                SerializedProperty property = this.m_Object.FindProperty(string.Format("m_LODs.Array.data[{0}].renderers", this.activeLOD));
                for (int j = property.arraySize - 1; j >= 0; j--)
                {
                    UnityEngine.Renderer objectReferenceValue = property.GetArrayElementAtIndex(j).FindPropertyRelative("renderer").objectReferenceValue as UnityEngine.Renderer;
                    if (objectReferenceValue == null)
                    {
                        property.DeleteArrayElementAtIndex(j);
                    }
                }
            }
            GUILayout.Space(17f);
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandWidth(true) };
            Rect totalRect = GUILayoutUtility.GetRect((float) 0f, (float) 30f, options);
            totalRect.width -= 14f;
            totalRect.x += 7f;
            List<LODInfo> lods = new List<LODInfo>();
            float screenPercent = -1f;
            for (int i = 0; i < this.m_NumberOfLODs; i++)
            {
                LODInfo info;
                SerializedProperty property3 = this.m_Object.FindProperty(string.Format("m_LODs.Array.data[{0}].screenRelativeHeight", i));
                info = new LODInfo(i, property3.floatValue) {
                    m_ButtonPosition = CalcLODButton(totalRect, info.ScreenPercent)
                };
                float startPercent = ((i - 1) >= 0) ? screenPercent : 1f;
                info.m_RangePosition = CalcLODRange(totalRect, startPercent, info.ScreenPercent);
                screenPercent = info.ScreenPercent;
                lods.Add(info);
            }
            GUILayout.Space(8f);
            this.DrawLODLevelSlider(totalRect, lods);
            GUILayout.Space(8f);
            GUILayout.Label(string.Format("LODBias of {0:0.00} active", QualitySettings.lodBias), EditorStyles.boldLabel, new GUILayoutOption[0]);
            if (((this.m_NumberOfLODs > 0) && (this.activeLOD >= 0)) && (this.activeLOD < this.m_NumberOfLODs))
            {
                this.DrawRenderersInfo(Screen.width / 60);
            }
            GUILayout.Space(8f);
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.Label("Recalculate:", EditorStyles.boldLabel, new GUILayoutOption[0]);
            if (GUILayout.Button(s_Styles.m_RecalculateBounds, new GUILayoutOption[0]))
            {
                LODUtility.CalculateLODGroupBoundingBox(base.target as LODGroup);
            }
            if (GUILayout.Button(s_Styles.m_LightmapScale, new GUILayoutOption[0]))
            {
                this.SendPercentagesToLightmapScale();
            }
            GUILayout.EndHorizontal();
            GUILayout.Space(5f);
            if (PrefabUtility.GetPrefabType(base.target) == PrefabType.ModelPrefabInstance)
            {
                ModelImporter importer = this.GetImporter();
                SerializedObject obj2 = new SerializedObject(importer);
                SerializedProperty property4 = obj2.FindProperty("m_LODScreenPercentages");
                bool flag3 = property4.isArray && (property4.arraySize == lods.Count);
                bool flag4 = GUI.enabled;
                if (!flag3)
                {
                    GUI.enabled = false;
                }
                if ((importer != null) && GUILayout.Button(!flag3 ? s_Styles.m_UploadToImporterDisabled : s_Styles.m_UploadToImporter, new GUILayoutOption[0]))
                {
                    for (int k = 0; k < property4.arraySize; k++)
                    {
                        property4.GetArrayElementAtIndex(k).floatValue = lods[k].RawScreenPercent;
                    }
                    obj2.ApplyModifiedProperties();
                    AssetDatabase.ImportAsset(importer.assetPath);
                }
                GUI.enabled = flag4;
            }
            this.m_Object.ApplyModifiedProperties();
            GUI.enabled = enabled;
        }

        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40f), "LOD preview \nnot available");
                }
            }
            else
            {
                this.InitPreview();
                this.m_PreviewDir = PreviewGUI.Drag2D(this.m_PreviewDir, r);
                this.m_PreviewDir.y = Mathf.Clamp(this.m_PreviewDir.y, -89f, 89f);
                if (Event.current.type == EventType.Repaint)
                {
                    this.m_PreviewUtility.BeginPreview(r, background);
                    this.DoRenderPreview();
                    Texture image = this.m_PreviewUtility.EndPreview();
                    GUI.DrawTexture(r, image, ScaleMode.StretchToFill, false);
                }
            }
        }

        public void OnSceneGUI()
        {
            if ((Application.HasProLicense() && (Event.current.type == EventType.Repaint)) && ((Camera.current != null) && (SceneView.lastActiveSceneView == SceneView.currentDrawingSceneView)))
            {
                Vector3 vector4 = Camera.current.transform.position - ((LODGroup) base.target).transform.position;
                if (Vector3.Dot(Camera.current.transform.forward, vector4.normalized) <= 0f)
                {
                    if (s_Styles == null)
                    {
                        s_Styles = new Styles();
                    }
                    Camera camera = SceneView.lastActiveSceneView.camera;
                    LODGroup target = base.target as LODGroup;
                    Vector3 position = target.transform.TransformPoint(target.localReferencePoint);
                    LODVisualizationInformation information = LODUtility.CalculateVisualizationData(camera, target, -1);
                    float worldSpaceSize = information.worldSpaceSize;
                    Handles.color = (information.activeLODLevel == -1) ? kCulledLODColor : kLODColors[information.activeLODLevel];
                    Handles.SelectionFrame(0, position, camera.transform.rotation, worldSpaceSize / 2f);
                    Vector3 vector2 = (Vector3) ((camera.transform.right * worldSpaceSize) / 2f);
                    Vector3 vector3 = (Vector3) ((camera.transform.up * worldSpaceSize) / 2f);
                    Vector3[] points = new Vector3[] { (position - vector2) + vector3, (position - vector2) - vector3, (position + vector2) + vector3, (position + vector2) - vector3 };
                    Rect rect = CalculateScreenRect(points);
                    float num2 = rect.x + (rect.width / 2f);
                    rect = new Rect(num2 - 100f, rect.yMax, 200f, 45f);
                    if (rect.yMax > (Camera.current.GetScreenHeight() - 45f))
                    {
                        rect.y = (Camera.current.GetScreenHeight() - 45f) - 40f;
                    }
                    Handles.BeginGUI();
                    GUI.Label(rect, GUIContent.none, EditorStyles.notificationBackground);
                    EditorGUI.DoDropShadowLabel(rect, GUIContent.Temp((information.activeLODLevel < 0) ? "Culled" : ("LOD " + information.activeLODLevel)), s_Styles.m_LODLevelNotifyText, 0.3f);
                    Handles.EndGUI();
                }
            }
        }

        private void SendPercentagesToLightmapScale()
        {
            List<LODLightmapScale> list = new List<LODLightmapScale>();
            for (int i = 0; i < this.m_NumberOfLODs; i++)
            {
                SerializedProperty property = this.m_Object.FindProperty(string.Format("m_LODs.Array.data[{0}].renderers", i));
                List<SerializedProperty> renderers = new List<SerializedProperty>();
                for (int k = 0; k < property.arraySize; k++)
                {
                    SerializedProperty item = property.GetArrayElementAtIndex(k).FindPropertyRelative("renderer");
                    if (item != null)
                    {
                        renderers.Add(item);
                    }
                }
                float scale = (i != 0) ? this.m_Object.FindProperty(string.Format("m_LODs.Array.data[{0}].screenRelativeHeight", i - 1)).floatValue : 1f;
                list.Add(new LODLightmapScale(scale, renderers));
            }
            for (int j = 0; j < this.m_NumberOfLODs; j++)
            {
                SetLODLightmapScale(list[j]);
            }
        }

        private static void SetLODLightmapScale(LODLightmapScale lodRenderer)
        {
            foreach (SerializedProperty property in lodRenderer.m_Renderers)
            {
                SerializedObject obj2 = new SerializedObject(property.objectReferenceValue);
                obj2.FindProperty("m_ScaleInLightmap").floatValue = Mathf.Max((float) 0f, (float) (lodRenderer.m_Scale * (1f / LightmapVisualization.GetLightmapLODLevelScale((UnityEngine.Renderer) property.objectReferenceValue))));
                obj2.ApplyModifiedProperties();
            }
        }

        private void SetSelectedLODLevelPercentage(float newScreenPercentage, List<LODInfo> lods)
        {
            <SetSelectedLODLevelPercentage>c__AnonStorey3F storeyf = new <SetSelectedLODLevelPercentage>c__AnonStorey3F {
                lods = lods,
                <>f__this = this
            };
            IEnumerable<LODInfo> source = Enumerable.Where<LODInfo>(storeyf.lods, new Func<LODInfo, bool>(storeyf.<>m__89));
            float screenPercent = 0f;
            if (source.FirstOrDefault<LODInfo>() != null)
            {
                screenPercent = source.FirstOrDefault<LODInfo>().ScreenPercent;
            }
            IEnumerable<LODInfo> enumerable2 = Enumerable.Where<LODInfo>(storeyf.lods, new Func<LODInfo, bool>(storeyf.<>m__8A));
            float num2 = 1f;
            if (enumerable2.FirstOrDefault<LODInfo>() != null)
            {
                num2 = enumerable2.FirstOrDefault<LODInfo>().ScreenPercent;
            }
            num2 = Mathf.Clamp01(num2);
            screenPercent = Mathf.Clamp01(screenPercent);
            storeyf.lods[this.m_SelectedLODSlider].ScreenPercent = Mathf.Clamp(newScreenPercentage, screenPercent, num2);
            this.m_Object.FindProperty(string.Format("m_LODs.Array.data[{0}].screenRelativeHeight", storeyf.lods[this.m_SelectedLODSlider].m_LODLevel)).floatValue = storeyf.lods[this.m_SelectedLODSlider].RawScreenPercent;
        }

        public void Update()
        {
            if (((SceneView.lastActiveSceneView != null) && (SceneView.lastActiveSceneView.camera != null)) && !Mathf.Approximately(0f, Vector3.Distance(SceneView.lastActiveSceneView.camera.transform.position, this.m_LastCameraPos)))
            {
                this.m_LastCameraPos = SceneView.lastActiveSceneView.camera.transform.position;
                base.Repaint();
            }
        }

        private static void UpdateCamera(float desiredPercentage, LODGroup group)
        {
            Vector3 position = group.transform.TransformPoint(group.localReferencePoint);
            float size = LODUtility.CalculateDistance(SceneView.lastActiveSceneView.camera, (desiredPercentage > 0f) ? desiredPercentage : 1E-06f, group);
            if (SceneView.lastActiveSceneView.camera.orthographic)
            {
                size = Mathf.Sqrt((size * size) * (1f + SceneView.lastActiveSceneView.camera.aspect));
            }
            SceneView.lastActiveSceneView.LookAtDirect(position, SceneView.lastActiveSceneView.camera.transform.rotation, size);
        }

        private void UpdateSelectedLODFromCamera(IEnumerable<LODInfo> lods, float cameraPercent)
        {
            IEnumerator<LODInfo> enumerator = lods.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    LODInfo current = enumerator.Current;
                    if (cameraPercent > current.RawScreenPercent)
                    {
                        this.m_SelectedLOD = current.m_LODLevel;
                        return;
                    }
                }
            }
            finally
            {
                if (enumerator == null)
                {
                }
                enumerator.Dispose();
            }
        }

        private int activeLOD
        {
            get
            {
                return this.m_SelectedLOD;
            }
        }

        [CompilerGenerated]
        private sealed class <GetRenderers>c__AnonStorey3E
        {
            internal LODGroup lodGroup;

            internal bool <>m__7F(GameObject go)
            {
                return go.transform.IsChildOf(this.lodGroup.transform);
            }

            internal bool <>m__80(GameObject go)
            {
                return !go.transform.IsChildOf(this.lodGroup.transform);
            }
        }

        [CompilerGenerated]
        private sealed class <HandleAddRenderer>c__AnonStorey3D
        {
            internal Event evt;

            internal bool <>m__7C(Rect x)
            {
                return !x.Contains(this.evt.mousePosition);
            }
        }

        [CompilerGenerated]
        private sealed class <SetSelectedLODLevelPercentage>c__AnonStorey3F
        {
            internal LODGroupEditor <>f__this;
            internal List<LODGroupEditor.LODInfo> lods;

            internal bool <>m__89(LODGroupEditor.LODInfo lod)
            {
                return (lod.m_LODLevel == (this.lods[this.<>f__this.m_SelectedLODSlider].m_LODLevel + 1));
            }

            internal bool <>m__8A(LODGroupEditor.LODInfo lod)
            {
                return (lod.m_LODLevel == (this.lods[this.<>f__this.m_SelectedLODSlider].m_LODLevel - 1));
            }
        }

        private class LODAction
        {
            private readonly Callback m_Callback;
            private readonly Vector2 m_ClickedPosition;
            private readonly List<LODGroupEditor.LODInfo> m_LODs;
            private readonly SerializedObject m_ObjectRef;
            private readonly float m_Percentage;

            public LODAction(List<LODGroupEditor.LODInfo> loDs, float percentage, Vector2 clickedPosition, SerializedObject objectRef, Callback callback)
            {
                this.m_LODs = loDs;
                this.m_Percentage = percentage;
                this.m_ClickedPosition = clickedPosition;
                this.m_ObjectRef = objectRef;
                this.m_Callback = callback;
            }

            public void DeleteLOD()
            {
                if (this.m_LODs.Count > 0)
                {
                    foreach (LODGroupEditor.LODInfo info in this.m_LODs)
                    {
                        int arraySize = this.m_ObjectRef.FindProperty(string.Format("m_LODs.Array.data[{0}].renderers", info.m_LODLevel)).arraySize;
                        if (info.m_RangePosition.Contains(this.m_ClickedPosition) && ((arraySize == 0) || EditorUtility.DisplayDialog("Delete LOD", "Are you sure you wish to delete this LOD?", "Yes", "No")))
                        {
                            this.m_ObjectRef.FindProperty(string.Format("m_LODs.Array.data[{0}]", info.m_LODLevel)).DeleteCommand();
                            this.m_ObjectRef.ApplyModifiedProperties();
                            if (this.m_Callback != null)
                            {
                                this.m_Callback();
                            }
                            break;
                        }
                    }
                }
            }

            public void InsertLOD()
            {
                SerializedProperty property = this.m_ObjectRef.FindProperty("m_LODs");
                if (property.isArray)
                {
                    int index = -1;
                    foreach (LODGroupEditor.LODInfo info in this.m_LODs)
                    {
                        if (this.m_Percentage > info.RawScreenPercent)
                        {
                            index = info.m_LODLevel;
                            break;
                        }
                    }
                    if (index < 0)
                    {
                        property.InsertArrayElementAtIndex(this.m_LODs.Count);
                        index = this.m_LODs.Count;
                    }
                    else
                    {
                        property.InsertArrayElementAtIndex(index);
                    }
                    this.m_ObjectRef.FindProperty(string.Format("m_LODs.Array.data[{0}].renderers", index)).arraySize = 0;
                    property.GetArrayElementAtIndex(index).FindPropertyRelative("screenRelativeHeight").floatValue = this.m_Percentage;
                    if (this.m_Callback != null)
                    {
                        this.m_Callback();
                    }
                    this.m_ObjectRef.ApplyModifiedProperties();
                }
            }

            public delegate void Callback();
        }

        private class LODInfo
        {
            public Rect m_ButtonPosition;
            public readonly int m_LODLevel;
            public Rect m_RangePosition;
            private float m_ScreenPercentage;

            public LODInfo(int lodLevel, float screenPercentage)
            {
                this.m_LODLevel = lodLevel;
                this.m_ScreenPercentage = screenPercentage;
            }

            public float RawScreenPercent
            {
                get
                {
                    return this.m_ScreenPercentage;
                }
            }

            public float ScreenPercent
            {
                get
                {
                    return LODGroupEditor.DelinearizeScreenPercentage(this.m_ScreenPercentage);
                }
                set
                {
                    this.m_ScreenPercentage = LODGroupEditor.LinearizeScreenPercentage(value);
                }
            }
        }

        private class LODLightmapScale
        {
            public readonly List<SerializedProperty> m_Renderers;
            public readonly float m_Scale;

            public LODLightmapScale(float scale, List<SerializedProperty> renderers)
            {
                this.m_Scale = scale;
                this.m_Renderers = renderers;
            }
        }

        private class Styles
        {
            public const int kButtonPadding = 2;
            public const int kDeleteButtonSize = 20;
            public const int kRenderAreaBackgroundPadding = 3;
            public const int kRenderAreaForegroundPadding = 6;
            public const int kRenderersButtonHeight = 60;
            public const int kSceneHeaderOffset = 40;
            public const int kSceneLabelHalfWidth = 100;
            public const int kSceneLabelHeight = 0x2d;
            public const int kSelectedLODRangePadding = 3;
            public const int kSliderBarHeight = 30;
            public const int kSliderBarPadding = 7;
            public readonly GUIContent m_CameraIcon = EditorGUIUtility.IconContent("Camera Icon");
            public readonly GUIContent m_IconRendererMinus = EditorGUIUtility.IconContent("Toolbar Minus", "Remove Renderer");
            public readonly GUIContent m_IconRendererPlus = EditorGUIUtility.IconContent("Toolbar Plus", "Add New Renderers");
            public readonly GUIContent m_LightmapScale = new GUIContent("Lightmap Scale", "Set the lightmap scale to match the LOD percentages");
            public readonly GUIStyle m_LODBlackBox = "LODBlackBox";
            public readonly GUIStyle m_LODCameraLine = "LODCameraLine";
            public readonly GUIStyle m_LODLevelNotifyText = "LODLevelNotifyText";
            public readonly GUIStyle m_LODRendererAddButton = "LODRendererAddButton";
            public readonly GUIStyle m_LODRendererButton = "LODRendererButton";
            public readonly GUIStyle m_LODRendererRemove = "LODRendererRemove";
            public readonly GUIStyle m_LODRenderersText = "LODRenderersText";
            public readonly GUIStyle m_LODSceneText = "LODSceneText";
            public readonly GUIStyle m_LODSliderBG = "LODSliderBG";
            public readonly GUIStyle m_LODSliderRange = "LODSliderRange";
            public readonly GUIStyle m_LODSliderRangeSelected = "LODSliderRangeSelected";
            public readonly GUIStyle m_LODSliderText = "LODSliderText";
            public readonly GUIStyle m_LODSliderTextSelected = "LODSliderTextSelected";
            public readonly GUIStyle m_LODStandardButton = "Button";
            public readonly GUIContent m_RecalculateBounds = new GUIContent("Bounds", "Recalculate bounds for the current LOD group.");
            public readonly GUIContent m_RendersTitle = new GUIContent("Renderers:");
            public readonly GUIContent m_UploadToImporter = new GUIContent("Upload to Importer", "Upload the modified screen percentages to the model importer.");
            public readonly GUIContent m_UploadToImporterDisabled = new GUIContent("Upload to Importer", "Number of LOD's in the scene instance differ from the number of LOD's in the imported model.");
        }
    }
}

